/**
 * Copyright 2019 [shujiang.yang], Inc. All rights reserved.
 * Email: 314938230@qq.com
**/
package awd.bj.jls.webs.controller;

import java.util.Date;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSON;

import awd.bj.jls.model.JjModel;
import awd.bj.jls.webs.api.JlsServersApi;
import awd.bj.jls.webs.api.model.User;
import awd.bj.jls.webs.utils.Result;
import awd.bj.jls.webs.utils.ResultUtils;

@Controller
@RequestMapping("/jjSyszyj")
@RefreshScope
public class JjSyszyjAction extends BaseAction {

    @Autowired
    private JlsServersApi jlsServersApi;

    @RequestMapping({"/jjSyszyj.html" //首页
            ,"/jjSyszyj_enter.html" //单表录入页面
            ,"/jjSyszyj_jbxx_enter.html" //人员信息查询页面
            ,"/jjSyszyj_query.html" //信息查询
            ,"/jjSyszyj_jbxx_query.html" //关联基本信息查询
            ,"/6.html" //
            ,"/7.html"})
    public String index(Model model, HttpServletRequest request) {
        model.addAllAttributes(getBaseModelData());
        return getRenderFilePath(request);
    }


    /**
     * 数据保存操作
     * @param model
     * @return
     */
    @RequestMapping("/save")
    @ResponseBody
    public Result<?> save(@ModelAttribute JjModel model){
        User users = getCurrentUser();
        System.out.println("\33[34;4m张天啸，械具使用-所长意见：接收前台的参数"+ JSON.toJSONString(model)+"\33[30;0m");
        try {
            model.setState("R2");
            model.setJsbh(users.getJsbh());
            model.setCreatetime(new Date());
            model.setCreator(users.getUsername());
            System.out.println("\33[32;4m，张天啸械具使用-所长意见：传往后台的参数"+ JSON.toJSONString(model)+"\33[30;0m");
            return ResultUtils.success("保存成功");
            //return ResultUtils.success(jlsServersApi.jjSave(model));
        } catch (Exception e) {
            e.printStackTrace();
            return ResultUtils.error(Result.ERR_SAVE, "保存失败");
        }
    }



}